import { BaseInjectHandler } from "../BaseInjectHandler";
import { EMessageC2C } from "../../../common/EMessageC2C";
import { HandleQueryObjList } from "./HandleQueryObjList";
import { TransPack } from "../../../server/framework/common/TransPack";
import { CommonOperateBack } from "../common/CommonOperateBack";
import { NodeDetailHelper } from "../action/NodeDetailHelper";
import { Data_Vec3 } from "../common/Data_Vec3";

export class HandleSetLocalRot extends BaseInjectHandler {

    msgId: number = EMessageC2C.SetLocalRot;

    private _listHandle: HandleQueryObjList;

    _OnInit() {
        this._listHandle = this.owner.GetHandleById(EMessageC2C.QueryObjList) as HandleQueryObjList;
    }

    _OnHandleMsg(msg: TransPack) {
        let getId = msg.data.id;
        let setRot = msg.data.rot as Data_Vec3;
        let getNode = this._listHandle.GetNodeById(getId);
        let backCode = new CommonOperateBack();
        if (getNode == null || getNode.destroyed) {
            backCode.code = -1;
            this.owner.SendTransOtherData(EMessageC2C.CommonOperate_Back, backCode);
            return;
        }
        if (getNode instanceof Laya.Sprite3D) {
            getNode.transform.localRotationEulerX = setRot.x;
            getNode.transform.localRotationEulerY = setRot.y;
            getNode.transform.localRotationEulerZ = setRot.z;
            backCode.code = 0;
        } else {
            backCode.code = -1;
        }
        this.owner.SendTransOtherData(EMessageC2C.CommonOperate_Back, backCode);
    }

}